package com.tianmenguide.wxapi;

import com.github.pagehelper.Page;
import com.tianmenguide.common.core.domain.AjaxResult;
import com.tianmenguide.guide.domain.Banners;
import com.tianmenguide.guide.domain.TravelGuides;
import com.tianmenguide.guide.service.IBannersService;
import com.tianmenguide.guide.service.ITravelGuidesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageImpl;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.tianmenguide.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/wxapi")
@RequiredArgsConstructor
@Api(tags = "旅游攻略wxapi")
public class WxTravelGuidesController {

    private final ITravelGuidesService travelGuidesService;

    @GetMapping("/loadTravelGuides")
    @ApiOperation("查询旅游攻略列表")
    public AjaxResult loadTravelGuides(TravelGuides travelGuides){
        startPage();
        List<TravelGuides> travelGuidesList = travelGuidesService.selectTravelGuidesList(travelGuides);
        Page<TravelGuides> page = (Page<TravelGuides>) travelGuidesList;
        int total = page.getPages();
        Map<String, Object> result = new HashMap<>();
        result.put("total", total);
        result.put("data", travelGuidesList);
        return AjaxResult.success(result);
    }
    /**
     * 获取游玩攻略管理详细信息
     */
    @ApiOperation("获取游玩攻略管理详细信息")
    @GetMapping(value = "/loadTravelGuides/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(travelGuidesService.selectTravelGuidesById(id));
    }
}
